package com.poxz.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * 日志切面
 *
 * @author poxz
 */
@Aspect
@Component
@Slf4j
public class LogAspect {
    /**
     * 日志切点
     */
    @Pointcut("execution(* com.poxz.controller.*.*(..))")
    public void logPointCut() {}

    /**
     * 前置通知
     *
     * @param joinPoint 切点
     */
    @Before("logPointCut()")
    public void doBefore(JoinPoint joinPoint) {
        String methodName = joinPoint.getSignature().getName();
        String className = joinPoint.getTarget().getClass().getName();
        log.info("方法开始执行：{}.{}, 参数：{}",
                className, methodName, Arrays.toString(joinPoint.getArgs()));
    }
}
